package com.itheima.app.controller;

import com.itheima.app.manager.MovementManager;
import com.itheima.domain.mongo.Movement;
import com.itheima.vo.PageBeanVo;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Map;

@RestController
public class MovementController {
    @Autowired
    private MovementManager movementManager;
    //发布动态
    @PostMapping("/movements")
    public void saveMovement(Movement movement, MultipartFile[] imageContent) throws IOException {
        movementManager.saveMovement(movement,imageContent);
    }
    //查看我的动态
    @GetMapping("/movements/all")
    public ResponseEntity findMyMovement(@RequestParam(value = "page",defaultValue = "1")Integer pageNum,
                                         @RequestParam(value = "pagesize",defaultValue = "10") Integer pageSize,
                                         Long userId){
        return movementManager.findMyMovement(userId,pageNum,pageSize);
    }
    //查看好友动态
    @GetMapping("/movements")
    public ResponseEntity findFriendMovement(@RequestParam(value = "page",defaultValue = "1")Integer pageNum,
                                             @RequestParam(value = "pagesize",defaultValue = "10") Integer pageSize){
        return movementManager.findFriendMovement(pageNum,pageSize);
    }
    //查看推荐动态
    @GetMapping("/movements/recommend")
    public ResponseEntity findRecommendMovement(@RequestParam(value = "page",defaultValue = "1")Integer pageNum,
                                                @RequestParam(value = "pagesize",defaultValue = "10") Integer pageSize){
        return movementManager.findRecommendMovement(pageNum,pageSize);
    }
    //动态点赞
    @GetMapping("/movements/{publishId}/like")
    public ResponseEntity setMovementLike(@PathVariable String publishId){
        return movementManager.setMovementLike(publishId);
    }
   //动态取消点赞
    @GetMapping("/movements/{publishId}/dislike")
    public ResponseEntity removeMovementLike(@PathVariable String publishId){
        return movementManager.removeMovementLike(publishId);
    }
    //动态喜欢
    @GetMapping("/movements/{publishId}/love")
    public ResponseEntity setMovementLove(@PathVariable String publishId){
        return movementManager.setMovementLove(publishId);
    }
    //动态取消喜欢
    @GetMapping("/movements/{publishId}/unlove")
    public ResponseEntity removeMovementLove(@PathVariable String publishId){
        return movementManager.removeMovementLove(publishId);
    }
    //查询动态留言详情页中的用户信息
    @GetMapping("/movements/{publishId}")
    public ResponseEntity findOneMovement(@PathVariable String publishId){
        return movementManager.findOneMovement(publishId);
    }
    //查询动态留言详情页中的所有留言
    @GetMapping("/comments")
    public ResponseEntity findMovementCommentByPage(@RequestParam("movementId") String publishId,
                                                    @RequestParam(value = "page",defaultValue = "1")Integer pageNum,
                                                    @RequestParam(value = "pagesize",defaultValue = "10") Integer pageSize
                                                    ){
        return movementManager.findMovementCommentByPage(pageNum,pageSize,publishId);
    }
    //发表评论
    @PostMapping("/comments")
    public void saveMovementComment(@RequestBody Map<String ,String > map){
        String publishId = map.get("movementId");
        String content = map.get("comment");
        movementManager.saveMovementComment(publishId,content);
    }

    @GetMapping("/comments/{publishId}/like")
    public ResponseEntity saveContentLike(@PathVariable String  publishId){
        return movementManager.saveContentLike(new ObjectId(publishId));
    }

    @GetMapping("/comments/{publishId}/dislike")
    public ResponseEntity delContentLike(@PathVariable String  publishId){
        return movementManager.delContentLike(new ObjectId(publishId));
    }

}
